import { IsPC } from '@/utils/judgePC'

const state = {
  isPC: true,
  screenWidth: document.body.clientWidth,
  screenHeight: document.body.clientHeight
}

const mutations = {
  SET_IS_PC(state, flag) {
    state.isPC = flag
  },

  SET_SCREEN(state, data) {
    state.screenWidth = data.screenWidth
    state.screenHeight = data.screenHeight
  },

  SET_SCREEN_HEIGHT(state, height) {
    // state.screenWidth = data.screenWidth
    state.screenHeight = height
  }
}

const actions = {
  getEquipmentInfo({ commit }) {
    const isPC = IsPC()
    const screenData = {
      /**
       * when init bom tree
       * dynamic bom tree can not get body clientHeight
       * first time screenHeight is 0
       * when dray border refresh screenWidth/screenHeight
       */
      screenWidth: document.body.clientWidth,
      // screenHeight: document.body.clientHeight
      screenHeight: window.innerHeight
    }
    commit('SET_IS_PC', isPC)
    commit('SET_SCREEN', screenData)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
